package utils

import (
	"center-platform/config"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var DB *gorm.DB

func InitDB() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		config.GlobalConfig.DB.User,
		config.GlobalConfig.DB.Password,
		config.GlobalConfig.DB.Host,
		config.GlobalConfig.DB.Port,
		config.GlobalConfig.DB.Database,
	)
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})

	if err != nil {
		panic(err.Error())
	}
	DB = db
	fmt.Println("--------mysql加载成功-------")
}
